import 'package:flutter/material.dart';

class DropdownButtonExample extends StatefulWidget {
  @override
  _DropdownButtonExampleState createState() => _DropdownButtonExampleState();
}

class _DropdownButtonExampleState extends State<DropdownButtonExample> {
  String selectedValue = '';
  List dropdownList = ['One', 'Two'];

  @override
  void initState() {
    selectedValue = dropdownList.first;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("DropdownButtonExample"),
      ),
      body: Center(
        child: DropdownButton(
          icon: Icon(Icons.arrow_downward),
          value: selectedValue,
          items: dropdownList
              .map((e) => DropdownMenuItem(
                    child: Text(e),
                    value: e,
                  ))
              .toList(),
          onChanged: (newValue) {
            setState(() {
              print(newValue);
              selectedValue = newValue;
            });
          },
        ),
      ),
    );
  }
}
